/****
* Title: Student Randomizer
*
* Author: Lyle Kozloff
*
* Description: Displays exciting colors and random names until you click - then
* displays a single, static name on an ominous screen. Names are not repeated until
* the class list has been exhausted once.
*
* Assumptions: MAXLENGTH will be greater than the number of lines in your file.
* FILENAME will be the correct path and filename.
* DISPSIZE will be the size you want displayed, less than 500 not reccommended.
* FONTNAME will be the file name of a font you've pre-created. You may need to change it!
****/finalint MAXLENGTH =50;finalString FILENAME ="grade7.txt";finalint DISPSIZE =600;finalString FONTNAME ="CharterBT-Roman-48.vlw";
PFont f;BufferedReader reader;String line ="";//trick our while conditionString[] students =newString[MAXLENGTH];//can't have more than MAXLENGTH students at a timeint loopCounter =0;int count =0;//set up drawing area, load fonts, read file and create randomized arrayvoid setup(){
size(DISPSIZE, DISPSIZE);
f = loadFont(FONTNAME);//This is how you read from a file.
reader = createReader(FILENAME);while(line!=null){try{
line = reader.readLine();//read a single line}catch(IOException e){
e.printStackTrace();
line =null;//if this happens, it's the end of the file.}if(line ==null){// Stop reading because of an error or file is emptybreak;}
students[loopCounter]= line;//put the name of a student in the next position in the array
loopCounter++;}//randomize the array
students = randomizeArray(students, loopCounter);}//what to do while we waitvoid draw(){
background(random(200,255),random(200,255),random(200,255));
textFont(f,24);
fill(0);
text(students[int(random(students.length))],random(DISPSIZE),random(DISPSIZE));
textFont(f,48);
textAlign(CENTER);
text("Click and HOLD!", DISPSIZE/2, DISPSIZE/2);}//What to do if the mouse is held downvoid mousePressed(){
noLoop();//stop looping on draw();// make sure that we aren't going out of boundsif(count>=students.length){//if we are going out of bounds, re-randomized the array
students = randomizeArray(students, students.length);
count =0;//reset the position}// display the next name on the randomized list
background(128,128,128);
textAlign(CENTER);
text(students[count], DISPSIZE/2, DISPSIZE/2);
count++;//increment to next student on the randomized list}//What to do if the mouse is releasedvoid mouseReleased(){
loop();//go back to draw();}//returns a randomized subset of kids of length arrlengthprivateString[] randomizeArray(String[] kids, int arrlength){String buffer;String[] randomizedArray =newString[arrlength];int position =0;int randPos =0;while(position<arrlength){
randPos =int(random(arrlength));
buffer = kids[randPos];
kids[randPos]=null;//don't want that kid again!if(buffer!=null){
randomizedArray[position]= buffer;//println(randomizedArray[position]);
position++;}}return randomizedArray;}